package com.suneee.refund.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.suneee.context.page.Page;
import com.suneee.context.page.Sort;
import com.suneee.context.page.Sort.Order;
import com.suneee.core.util.StringUtils;
import com.suneee.orm.GenericDao;
import com.suneee.orm.util.WhereClauseBuilder;
import com.suneee.refund.bean.FinancialOfflineInfoSearchBean;
import com.suneee.refund.dao.FinancialOfflineInfoDao;
import com.suneee.refund.entity.FinancialOfflineInfo;

@Repository("financialOfflineInfoDao")
public class FinancialOfflineInfoDaoImpl extends GenericDao<FinancialOfflineInfo, Integer>implements FinancialOfflineInfoDao {


	@Override
	public Page<FinancialOfflineInfo> findFinancialOfflineInfo(FinancialOfflineInfoSearchBean bean) {
		if (bean == null) {
			bean = new FinancialOfflineInfoSearchBean();
		}
		WhereClauseBuilder builder = new WhereClauseBuilder();
		builder.contains("enterprise_code", bean.getEnterpriseCode());
		builder.equals("buyer_account", bean.getBuyerAccount());
		builder.equals("sup_code", bean.getSpuCode());
		builder.equals("sup_name", bean.getSpuName());
		builder.contains("type", bean.getType());
		builder.equals("order_id", bean.getOrderId());
		bean.setPageNumber(bean.getPageNumber() == 0 ? 1 : bean.getPageNumber());
		bean.setPageSize(bean.getPageSize() == 0 ? 10 : bean.getPageSize());
		bean.setSort((bean.getSort() == null || StringUtils.isEmpty(bean.getSort().getOrderByClause()))
				? new Sort("id", Order.DESC) : bean.getSort());
		return selectWhere(builder.getSql(), bean, builder.getArgs());
	}

	@Override
	public List<FinancialOfflineInfo> listEnterpriseFinancialOfflineInfo(String enterpriseCode) {
		return this.selectWhere(" enterprise_code", enterpriseCode);
	}

	

	
}
